package sg.edu.nus.iss.phoenix.radioprogram.delegate;

import java.util.ArrayList;

import sg.edu.nus.iss.phoenix.radioprogram.entity.RPSearchObject;
import sg.edu.nus.iss.phoenix.radioprogram.entity.RadioProgram;
import sg.edu.nus.iss.phoenix.radioprogram.service.RadioProgramService;

/**
 * RadioProgram Delegate. This class calls the service to invoke an action.
 * 
 * @author Desmond Quek (A0092681)
 * @version 1.0 2012/9/26
 */
public class RPDelegate {

  /**
	 * Returns a list of radio programs by search
	 * 
	 * @param rpso Radio program search object
	 * @return
	 */
	public ArrayList<RadioProgram> searchPrograms(RPSearchObject rpso) {
		RadioProgram rp = new RadioProgram(rpso.getName());
		rp.setDescription(rpso.getDescription());
		RadioProgramService service = new RadioProgramService();
		return service.searchPrograms(rp);	
	}
	
  /**
	 * Search by criteria
	 * 
	 * @param rpso Radio program search object
	 * @return
	 */ 
	public ArrayList<RadioProgram> findRPByCriteria(RPSearchObject rpso) {
		RadioProgram rp = new RadioProgram(rpso.getName());
		rp.setDescription(rpso.getDescription());
		RadioProgramService service = new RadioProgramService();
		return service.searchPrograms(rp);	
	}
	
  /**
	 * Find radio program
	 * 
	 * @param rpName Radio program name
	 * @return
	 */ 
	public RadioProgram findRP(String rpName) {
		RadioProgram rp = new RadioProgram(rpName);
		RadioProgramService service = new RadioProgramService();
		return (service.searchPrograms(rp)).get(0);	
		
	}
   
  /**
	 * Find all radio programs
	 * 
	 * @return
	 */ 
	public ArrayList<RadioProgram> findAllRP() {
		RadioProgramService service = new RadioProgramService();
		return service.findAllRP();
		
	}
	
  /**
	 * Insert radio program
	 * 
	 * @param rp Radio program object
	 */ 
	public void insertRP(RadioProgram rp) {
		RadioProgramService service = new RadioProgramService();
		service.insertRP(rp);
		
	}
   
  /**
	 * Update radio program
	 * 
	 * @param rp Radio program object
	 */
	public void updateRP(RadioProgram rp) {
		RadioProgramService service = new RadioProgramService();
		service.updateRP(rp);
		
	}
   
  /**
	 * Delete radio program
	 * 
	 * @param rp Radio program object
	 */
	public void deleteRP(RadioProgram rp) {
		RadioProgramService service = new RadioProgramService();
		service.deleteRP(rp);
	}
}
